//
//  HMNavigationViewController.swift
//  微博
//
//  Created by 程双岐 on 16/9/20.
//  Copyright © 2016年 heima. All rights reserved.
//

import UIKit

class HMNavigationViewController: UINavigationController ,UIGestureRecognizerDelegate{

    override func viewDidLoad() {
        super.viewDidLoad()
        self.interactivePopGestureRecognizer?.delegate = self
    }

    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        if viewControllers.count > 0 {
            
            print(viewControllers.count)
            if viewControllers.count == 1 {
                let title = viewControllers.first!.title!
                viewController.navigationItem.leftBarButtonItem = UIBarButtonItem(title: title, imageName: "navigationbar_back_withtext", target: self, action: #selector(backAction))
                
            }else{
                viewController.navigationItem.leftBarButtonItem = UIBarButtonItem(title:"返回", imageName: "navigationbar_back_withtext", target: self, action: #selector(backAction))
            }
            
            viewController.title = "当前显示第\(viewControllers.count + 1)界面"
        }
        super.pushViewController(viewController, animated: animated)
    }

    func backAction(){
        popViewController(animated: true)
    }

    func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {
        if viewControllers.count == 1 {
            return false
        }
        return true
    }
    
    
}
